import requests

from config.config import REGISTER_URL, DEFAULT_HEADERS, LOGIN_URL, MANAGERLOGIN_URL, ADDITEM_PATH, admin_login


class Api(object):
    @classmethod
    def register(cls, req_data):
        resp = requests.post(url=REGISTER_URL,
                           json=req_data,
                           headers=DEFAULT_HEADERS)
        return resp

    @classmethod
    def login(cls, req_data):
        resp = requests.post(url=LOGIN_URL,
                           json=req_data,
                           headers=DEFAULT_HEADERS)
        return resp
    
    @classmethod
    def manager_login(cls, req_data):
        """管理员登录接口"""
        resp = requests.post(url=MANAGERLOGIN_URL,
                           json=req_data,
                           headers=DEFAULT_HEADERS)
        return resp
    
    @classmethod
    def add_item(cls, req_data, token):
        """添加商品接口"""
        headers = DEFAULT_HEADERS.copy()
        headers["Authorization"] = f"{token}"
        resp = requests.post(url=ADDITEM_PATH,
                           json=req_data,
                           headers=headers)
        return resp

